package org.anjoy.ktv.adapter;

import java.util.ArrayList;

import org.anjoy.ktv.R;
import org.anjoy.ktv.bean.Song;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class SongNameAdapter extends ArrayAdapter<Song> {

	private final LayoutInflater mInflater;
	private Context mContext;
	ArrayList<Song> songs;

	public SongNameAdapter(Context context, ArrayList<Song> songs) {
		super(context, 0, songs);
		mContext = context;
		mInflater = LayoutInflater.from(context);
		this.songs = songs;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Song song = songs.get(position);
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.ktv_songname_item, parent,
					false);
		}
		View view = convertView.findViewById(R.id.ktv_songname_bg);
		String type = song.getType();
		int resouceId = R.drawable.ktv_song_other_bg;
		if("1".equals(type)){
			resouceId = R.drawable.ktv_song_chinese_bg;
		}else if("2".equals(type)){
			resouceId = R.drawable.ktv_song_korean_bg;
		}else if("3".equals(type)){
			resouceId = R.drawable.ktv_song_japanese_bg;
		}else if("4".equals(type)){
			resouceId = R.drawable.ktv_song_cantonese_bg;
		}else if("5".equals(type)){
			resouceId = R.drawable.ktv_song_english_bg;
		}else if("6".equals(type)){
			resouceId = R.drawable.ktv_song_other_bg;
		}else if("7".equals(type)){
			resouceId = R.drawable.ktv_song_minnan_bg;
		}
		view.setBackgroundResource(resouceId);
		ImageView songAuthorImg = (ImageView)convertView.findViewById(R.id.song_author_img);
		songAuthorImg.setImageResource(R.drawable.ktv_mtv_default);
		
		TextView songName = (TextView)convertView.findViewById(R.id.song_name);
		songName.setText(song.getName());
		TextView starName = (TextView)convertView.findViewById(R.id.song_author_name);
		starName.setText(song.getStarName());
		return convertView;
	}

}
